<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="format-detection" content="telephone=no"/>
    <style type="text/css">
        .page {
            max-width: 640px;
            margin: -10px auto 10px;
        }
        .page_title {
            margin: 0px 5px !important;
        }
        .page_title .weui_btn {
            float: left;
            width: 30%;
            margin: 5px;
            line-height: 60px;
        }
        .clear {
            clear: both;
        }
        .weui_btn:first-child {
            position: relative;
            top: 10px;
        }
    </style>
    <title>赞赏{$_W['account']['name']}</title>
    <link rel="stylesheet" type="text/css" href="{RES}css/weui.css">
    <link rel="stylesheet" type="text/css" href="{RES}css/example.css">
    <script src="http://cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<div class="page cell">

    <div class="hd">
        <h1 class="page_title"><img src="{php echo tomedia('headimg_'.$account['acid'].'.jpg');}?time={php echo time()}" style="height: 50px;width: 50px;" /></h1>
        <p class="page_desc" style="font-size:18px;font-weight:bold;">{$account['name']}</p>
        <p class="page_desc">{$detail['admiretxt']}</p>
        <input type="hidden" id="artid" name="artid" value="{$artid}" />
    </div>
    <div class="hd">
        <h1 class="page_title">
            {loop $adsets $adset}
            <a href="javascript:;" class="weui_btn weui_btn_plain_primary" data-price="{$adset['price']}"><span style="font-size:18px;font-weight:bold;">{$adset['price']}</span>元
            </a>
            {/loop}
    </div>

    <div class="clear"></div>

    <div class="bd spacing">
        <div class="button_sp_area">
            <a href="javascript:;" class="weui_btn weui_btn_plain_primary" id="showDialog2">其他金额</a>
        </div>
    </div>

    <div class="weui_dialog_alert" id="dialog2" style="display: none;">
        <div class="weui_mask"></div>
        <div class="weui_dialog">
            <div class="weui_dialog_hd"> <a data-remodal-action="close" class="remodal-close" aria-label="Close">X</a>
                <strong class="weui_dialog_title">其他金额</strong></div>
            <div class="weui_dialog_bd">金额(元) <input class="weui_input" style="width: 75%;" type="number" name="price" id="price" placeholder="可填写1-256"></div>
            <div class="weui_dialog_ft">
                <a href="javascript:;" class="weui_btn_dialog primary">赞赏</a>
            </div>
        </div>
    </div>

    <div class="weui_msg"  style="display: none;">
        <div class="weui_icon_area"><i class="weui_icon_success weui_icon_msg"></i></div>
        <div class="weui_text_area">
            <h2 class="weui_msg_title">操作成功</h2>
            <p class="weui_msg_desc">内容详情，可根据实际需要安排</p>
        </div>
        <div class="weui_opr_area">
            <p class="weui_btn_area">
                <a href="javascript:;" class="weui_btn weui_btn_primary">确定</a>
                <a href="javascript:;" class="weui_btn weui_btn_default">取消</a>
            </p>
        </div>
    </div>
</div>
</body>
<link href="http://cdn.bootcss.com/weui/0.4.0/style/weui.min.css" rel="stylesheet">

<div class="weui_dialog_alert" id="dialog2" style="display:none;">
    <div class="weui_mask"></div>
    <div class="weui_dialog">
        <div class="weui_dialog_hd"><strong class="weui_dialog_title">提示</strong></div>
        <div class="weui_dialog_bd">出错了。</div>
        <div class="weui_dialog_ft">
            <a href="javascript:hidemod('dialog2');"   class="weui_btn_dialog primary btn_hide">确定</a>
        </div>
    </div>
</div>
<div id="loadingToast" class="weui_loading_toast" style="display: none;">
    <div class="weui_mask_transparent"></div>
    <div class="weui_toast">
        <div class="weui_loading">
            <div class="weui_loading_leaf weui_loading_leaf_0"></div>
            <div class="weui_loading_leaf weui_loading_leaf_1"></div>
            <div class="weui_loading_leaf weui_loading_leaf_2"></div>
            <div class="weui_loading_leaf weui_loading_leaf_3"></div>
            <div class="weui_loading_leaf weui_loading_leaf_4"></div>
            <div class="weui_loading_leaf weui_loading_leaf_5"></div>
            <div class="weui_loading_leaf weui_loading_leaf_6"></div>
            <div class="weui_loading_leaf weui_loading_leaf_7"></div>
            <div class="weui_loading_leaf weui_loading_leaf_8"></div>
            <div class="weui_loading_leaf weui_loading_leaf_9"></div>
            <div class="weui_loading_leaf weui_loading_leaf_10"></div>
            <div class="weui_loading_leaf weui_loading_leaf_11"></div>
        </div>
        <p class="weui_toast_content">加载中...</p>
    </div>
</div>


<script type="text/javascript">

    function dialog2(msg){
        $("#dialog2 .weui_dialog_bd").html(msg);
        $("#dialog2").show();
    }
    function hidemod(boxid){
        $("#"+boxid).hide();
    }
    function loadingToast(msg){
        $("#loadingToast .weui_toast_content").html(msg);
        $("#loadingToast").show();
    }
</script>

<script type="text/javascript">

    function pay(price,aid){
        var price = price;
        if (!price) {
            price = 0.01;
        }
        var params ={
            'price':price,
            'artid':aid
        }; 
        $.ajax({
            type : "POST",
            url : "{php echo $this->createMobileUrl('admire', array('ty' => $_GPC['ty']))}",
            data : params,
            dataType : "json",
            beforeSend : function(XMLHttpRequest) {
                loadingToast("跳转支付...");
            },
            success : function(res){
                if(res.status==200){
                    window.location.href = res.pay_url;
                }else if(res.status == 201) {
                    dialog2(res.msg);
                }else{
                    hidemod("loadingToast");
                    dialog2(res.msg);
                }
            },
            error : function(data){
                hidemod("loadingToast");
                dialog2(data.msg);
            }
        });
    }

    $(function () {
        $(".button_sp_area .weui_btn").click(function () {
            $('#dialog2').show();
            $('#dialog2').find('.weui_btn_dialog').on('click', function () {
                var money = $("input[name='price']");
                if (money.val() == '') {
                    alert("请输入您要打赏金额");
                    money.focus();
                    return false;
                }
                var reg = new RegExp("^[0-9]+(.[0-9]{2})?$");
                if (!reg.test(money.val())) {
                    alert("请输入正确的打赏金额");
                    money.focus();
                    return false;
                }
                var price = parseFloat(money.val()); // 支付金额
                var aid=$('#artid').val();
                pay(price,aid);
            });
        });

        $(".remodal-close").click(function () {
            $('#dialog2').hide();
        });

        $(".page_title .weui_btn").click(function () {
            var price = $(this).attr('data-price'); // 支付金额
            var aid=$('#artid').val();

            pay(price,aid);
        });
    });

</script>
</html>